package com.demo.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Build;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.module.commonui.R;


public class LoadingDialog extends Dialog {
    private final TextView mMsgTv;
    private final ImageView mIv;

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.loadingdialog);
        setContentView(R.layout.pop_loading);
        mMsgTv = findViewById(R.id.load_tip);
        mIv = findViewById(R.id.doorbell_loading);
        if (getWindow() != null){
            getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        }

        setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                AnimationDrawable account_edit = (AnimationDrawable) mIv.getDrawable();
                account_edit.start();
            }
        });
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                AnimationDrawable account_edit = (AnimationDrawable) mIv.getDrawable();
                account_edit.stop();
            }
        });
        setCancelable(false);
    }

    public void setMsg(String msg) {
        if (mMsgTv!=null){
            mMsgTv.setText(msg);
        }

    }

    public void setMsg(int resId) {
        mMsgTv.setText(resId);
    }
}
